package com.cosina.game.crystallight.model.battle;

import java.lang.reflect.Field;

import com.cosina.game.crystallight.data.FieldInfo;

public class BattleFieldFactory {

	public static BattleField get(int id){
		try{
			return BattleFieldFactory.tryGet(id);
		}catch(Exception ex){
			IllegalArgumentException newEx = new IllegalArgumentException("can't create BattleField with id " + id,ex);
			throw newEx;
		}
	}

	public static BattleField tryGet(int id)throws Exception{
		Field groundField = FieldInfo.class.getDeclaredField("L" + id + "G");
		return new BattleFieldLoad(id,(int[][])groundField.get(null));
	}

	public static int getWaveCount(int id){
		try{
			Field groundField = FieldInfo.class.getDeclaredField("L" + id + "G");
			int[][] value = (int[][])groundField.get(null);
			return value.length - 10;
		}catch(Exception ex){
			IllegalArgumentException newEx = new IllegalArgumentException("can't get waveCount with id " + id,ex);
			throw newEx;
		}
	}

}
